/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.prdownloader.sample.slice;

import com.downloader.*;
import com.downloader.Error;
import com.downloader.utils.FileUtils;
import com.downloader.utils.L;
import com.prdownloader.sample.ResourceTable;
import com.prdownloader.sample.utils.Utils;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.components.ProgressBar;
import ohos.agp.components.Text;
import ohos.agp.window.dialog.ToastDialog;

import java.io.File;

public class MainAbilitySlice extends AbilitySlice {

    private static String dirPath;

    final String URL1 = "http://www.appsapk.com/downloading/latest/Facebook-119.0.0.23.70.apk";
    final String URL2 = "http://www.appsapk.com/downloading/latest/WeChat-6.5.7.apk";
    final String URL3 = "http://www.appsapk.com/downloading/latest/Instagram.apk";
    final String URL4 = "http://www.appsapk.com/downloading/latest/Emoji%20Flashlight%20-%20Brightest%20Flashlight%202018-2.0.1.apk";
    final String URL5 = "http://www.appsapk.com/downloading/latest/Screen%20Recorder-7.7.apk";
    final String URL6 = "http://www.appsapk.com/downloading/latest/Call%20Recorder%20-%20Automatic%20Call%20Recorder-1.6.0.apk";
    final String URL7 = "http://www.appsapk.com/downloading/latest/Sound%20Profile%20(+%20volume%20scheduler)-5.25.apk";
    final String URL8 = "http://www.appsapk.com/downloading/latest/Evernote%20-%20stay%20organized.-7.9.7.apk";
    final String URL9 = "http://www.appsapk.com/downloading/latest/UC-Browser.apk";
    final String URL10 = "http://www.appsapk.com/downloading/latest/Barcode%20Scanner-1.2.apk";
    final String URL11 = "http://download.blender.org/peach/bigbuckbunny_movies/BigBuckBunny_640x360.m4v";
    final String URL12 = "http://www2.sdfi.edu.cn/netclass/jiaoan/englit/download/Harry%20Potter%20and%20the%20Sorcerer's%20Stone.pdf";
    final String URL13 = "https://media.giphy.com/media/Bk0CW5frw4qfS/giphy.gif";
    final String URL14 = "http://techslides.com/demos/sample-videos/small.mp4";
    final String URL15 = "http://www.sample-videos.com/video/mp4/720/big_buck_bunny_720p_10mb.mp4";

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);

        dirPath = Utils.getRootDirPath(getApplicationContext());

        File file = new File("temp");
        FileUtils.createOrExistsDir(file);

        initComponent();
    }

    private void initComponent() {
        initOneDownload();
        initTowDownload();
        initThreeDownload();
        initFourDownload();
        initFiveDownload();
        initSixDownload();
        initSevenDownload();
        initEightDownload();
        initNineDownload();
        initTenDownload();
        initElevenDownload();
        initTwelveDownload();
        initThirteenDownload();
        initFourteenDownload();
        initFifteenDownload();
    }




    private int downloadIdOne, downloadIdTwo, downloadIdThree, downloadIdFour, downloadIdFive, downloadIdSix,
            downloadIdSeven, downloadIdEight, downloadIdNine, downloadIdTen, downloadIdEleven, downloadIdTwelve,
            downloadIdThirteen, downloadIdFourteen, downloadIdFifteen;

    private void initOneDownload() {
        ProgressBar progressBar = (ProgressBar) findComponentById(ResourceTable.Id_progressOne);
        Text progressText = (Text) findComponentById(ResourceTable.Id_progressOneText);
        Button cancelBtn = (Button) findComponentById(ResourceTable.Id_cancelOne);
        Button startBtn = (Button) findComponentById(ResourceTable.Id_startOne);
        cancelBtn.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                PRDownloader.cancel(downloadIdOne);
            }
        });
        startBtn.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                if (Status.RUNNING == PRDownloader.getStatus(downloadIdOne)) {
                    PRDownloader.pause(downloadIdOne);
                    return;
                }

                startBtn.setEnabled(false);
                progressBar.setIndeterminate(true);

                if (Status.PAUSED == PRDownloader.getStatus(downloadIdOne)) {
                    PRDownloader.resume(downloadIdOne);
                    return;
                }

                L.info(dirPath);
                downloadIdOne = PRDownloader.download(URL1, dirPath, "facebook.apk")
                        .build()
                        .setOnStartOrResumeListener(new OnStartOrResumeListener() {
                            @Override
                            public void onStartOrResume() {
                                progressBar.setIndeterminate(false);
                                startBtn.setEnabled(true);
                                startBtn.setText("PAUSE");
                                cancelBtn.setEnabled(true);
                            }
                        })
                        .setOnPauseListener(new OnPauseListener() {
                            @Override
                            public void onPause() {
                                startBtn.setText("RESTART");
                            }
                        })
                        .setOnCancelListener(new OnCancelListener() {
                            @Override
                            public void onCancel() {
                                startBtn.setText("START");
                                cancelBtn.setEnabled(false);
                                progressBar.setProgressValue(0);
                                progressText.setText("");
                                downloadIdOne = 0;
                                progressBar.setIndeterminate(false);
                            }
                        })
                        .setOnProgressListener(new OnProgressListener() {
                            @Override
                            public void onProgress(Progress progress) {
                                long progressPercent = progress.currentBytes * 100 / progress.totalBytes;
                                progressBar.setProgressValue((int) progressPercent);
                                progressText.setText(Utils.getProgressDisplayLine(progress.currentBytes, progress.totalBytes));
                                progressBar.setIndeterminate(false);
                            }
                        })
                        .start(new OnDownloadListener() {
                            @Override
                            public void onDownloadComplete() {
                                startBtn.setEnabled(false);
                                cancelBtn.setEnabled(false);
                                startBtn.setText("SUCCESS");
                            }

                            @Override
                            public void onError(Error error) {
                                startBtn.setText("START");

                                ToastDialog toastDialog = new ToastDialog(MainAbilitySlice.this);
                                toastDialog.setText("some_error_occurred 1").show();
                                progressText.setText("");
                                progressBar.setProgressValue(0);
                                downloadIdOne = 0;
                                cancelBtn.setEnabled(false);
                                progressBar.setIndeterminate(false);
                                startBtn.setEnabled(true);
                            }
                        });
            }
        });
    }

    private void initTowDownload() {
        ProgressBar progressBar = (ProgressBar) findComponentById(ResourceTable.Id_progressTwo);
        Button cancelBtn = (Button) findComponentById(ResourceTable.Id_cancelTwo);
        Button startBtn = (Button) findComponentById(ResourceTable.Id_startTwo);
        Text progressText = (Text) findComponentById(ResourceTable.Id_progressTwoText);
        cancelBtn.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                PRDownloader.cancel(downloadIdTwo);
            }
        });
        startBtn.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                if (Status.RUNNING == PRDownloader.getStatus(downloadIdTwo)) {
                    PRDownloader.pause(downloadIdTwo);
                    return;
                }

                startBtn.setEnabled(false);
                progressBar.setIndeterminate(true);

                if (Status.PAUSED == PRDownloader.getStatus(downloadIdTwo)) {
                    PRDownloader.resume(downloadIdTwo);
                    return;
                }

                downloadIdTwo = PRDownloader.download(URL2, dirPath, "facebook.apk")
                        .build()
                        .setOnStartOrResumeListener(new OnStartOrResumeListener() {
                            @Override
                            public void onStartOrResume() {
                                progressBar.setIndeterminate(false);
                                startBtn.setEnabled(true);
                                startBtn.setText("PAUSE");
                                cancelBtn.setEnabled(true);
                            }
                        })
                        .setOnPauseListener(new OnPauseListener() {
                            @Override
                            public void onPause() {
                                startBtn.setText("RESTART");
                            }
                        })
                        .setOnCancelListener(new OnCancelListener() {
                            @Override
                            public void onCancel() {
                                startBtn.setText("START");
                                cancelBtn.setEnabled(false);
                                progressBar.setProgressValue(0);
                                progressText.setText("");
                                downloadIdTwo = 0;
                                progressBar.setIndeterminate(false);
                            }
                        })
                        .setOnProgressListener(new OnProgressListener() {
                            @Override
                            public void onProgress(Progress progress) {
                                long progressPercent = progress.currentBytes * 100 / progress.totalBytes;
                                progressBar.setProgressValue((int) progressPercent);
                                progressText.setText(Utils.getProgressDisplayLine(progress.currentBytes, progress.totalBytes));
                                progressBar.setIndeterminate(false);
                            }
                        })
                        .start(new OnDownloadListener() {
                            @Override
                            public void onDownloadComplete() {
                                startBtn.setEnabled(false);
                                cancelBtn.setEnabled(false);
                                startBtn.setText("SUCCESS");
                            }

                            @Override
                            public void onError(Error error) {
                                startBtn.setText("START");

                                ToastDialog toastDialog = new ToastDialog(MainAbilitySlice.this);
                                toastDialog.setText("some_error_occurred 1").show();
                                progressText.setText("");
                                progressBar.setProgressValue(0);
                                downloadIdTwo = 0;
                                cancelBtn.setEnabled(false);
                                progressBar.setIndeterminate(false);
                                startBtn.setEnabled(true);
                            }
                        });
            }
        });
    }

    private void initThreeDownload() {
        ProgressBar progressBar = (ProgressBar) findComponentById(ResourceTable.Id_progressThree);
        Button cancelBtn = (Button) findComponentById(ResourceTable.Id_cancelThree);
        Button startBtn = (Button) findComponentById(ResourceTable.Id_startThree);
        Text progressText = (Text) findComponentById(ResourceTable.Id_progressThreeText);
        cancelBtn.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                PRDownloader.cancel(downloadIdThree);
            }
        });
        startBtn.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                if (Status.RUNNING == PRDownloader.getStatus(downloadIdThree)) {
                    PRDownloader.pause(downloadIdThree);
                    return;
                }

                startBtn.setEnabled(false);
                progressBar.setIndeterminate(true);

                if (Status.PAUSED == PRDownloader.getStatus(downloadIdThree)) {
                    PRDownloader.resume(downloadIdThree);
                    return;
                }

                downloadIdThree = PRDownloader.download(URL3, dirPath, "facebook.apk")
                        .build()
                        .setOnStartOrResumeListener(new OnStartOrResumeListener() {
                            @Override
                            public void onStartOrResume() {
                                progressBar.setIndeterminate(false);
                                startBtn.setEnabled(true);
                                startBtn.setText("PAUSE");
                                cancelBtn.setEnabled(true);
                            }
                        })
                        .setOnPauseListener(new OnPauseListener() {
                            @Override
                            public void onPause() {
                                startBtn.setText("RESTART");
                            }
                        })
                        .setOnCancelListener(new OnCancelListener() {
                            @Override
                            public void onCancel() {
                                startBtn.setText("START");
                                cancelBtn.setEnabled(false);
                                progressBar.setProgressValue(0);
                                progressText.setText("");
                                downloadIdThree = 0;
                                progressBar.setIndeterminate(false);
                            }
                        })
                        .setOnProgressListener(new OnProgressListener() {
                            @Override
                            public void onProgress(Progress progress) {
                                long progressPercent = progress.currentBytes * 100 / progress.totalBytes;
                                progressBar.setProgressValue((int) progressPercent);
                                progressText.setText(Utils.getProgressDisplayLine(progress.currentBytes, progress.totalBytes));
                                progressBar.setIndeterminate(false);
                            }
                        })
                        .start(new OnDownloadListener() {
                            @Override
                            public void onDownloadComplete() {
                                startBtn.setEnabled(false);
                                cancelBtn.setEnabled(false);
                                startBtn.setText("SUCCESS");
                            }

                            @Override
                            public void onError(Error error) {
                                startBtn.setText("START");

                                ToastDialog toastDialog = new ToastDialog(MainAbilitySlice.this);
                                toastDialog.setText("some_error_occurred 1").show();
                                progressText.setText("");
                                progressBar.setProgressValue(0);
                                downloadIdThree = 0;
                                cancelBtn.setEnabled(false);
                                progressBar.setIndeterminate(false);
                                startBtn.setEnabled(true);
                            }
                        });
            }
        });
    }

    private void initFourDownload() {
        ProgressBar progressBar = (ProgressBar) findComponentById(ResourceTable.Id_progressFour);
        Button cancelBtn = (Button) findComponentById(ResourceTable.Id_cancelFour);
        Button startBtn = (Button) findComponentById(ResourceTable.Id_startFour);
        Text progressText = (Text) findComponentById(ResourceTable.Id_progressFourText);
        cancelBtn.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                PRDownloader.cancel(downloadIdFour);
            }
        });
        startBtn.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                if (Status.RUNNING == PRDownloader.getStatus(downloadIdFour)) {
                    PRDownloader.pause(downloadIdFour);
                    return;
                }

                startBtn.setEnabled(false);
                progressBar.setIndeterminate(true);

                if (Status.PAUSED == PRDownloader.getStatus(downloadIdFour)) {
                    PRDownloader.resume(downloadIdFour);
                    return;
                }

                downloadIdFour = PRDownloader.download(URL4, dirPath, "facebook.apk")
                        .build()
                        .setOnStartOrResumeListener(new OnStartOrResumeListener() {
                            @Override
                            public void onStartOrResume() {
                                progressBar.setIndeterminate(false);
                                startBtn.setEnabled(true);
                                startBtn.setText("PAUSE");
                                cancelBtn.setEnabled(true);
                            }
                        })
                        .setOnPauseListener(new OnPauseListener() {
                            @Override
                            public void onPause() {
                                startBtn.setText("RESTART");
                            }
                        })
                        .setOnCancelListener(new OnCancelListener() {
                            @Override
                            public void onCancel() {
                                startBtn.setText("START");
                                cancelBtn.setEnabled(false);
                                progressBar.setProgressValue(0);
                                progressText.setText("");
                                downloadIdFour = 0;
                                progressBar.setIndeterminate(false);
                            }
                        })
                        .setOnProgressListener(new OnProgressListener() {
                            @Override
                            public void onProgress(Progress progress) {
                                long progressPercent = progress.currentBytes * 100 / progress.totalBytes;
                                progressBar.setProgressValue((int) progressPercent);
                                progressText.setText(Utils.getProgressDisplayLine(progress.currentBytes, progress.totalBytes));
                                progressBar.setIndeterminate(false);
                            }
                        })
                        .start(new OnDownloadListener() {
                            @Override
                            public void onDownloadComplete() {
                                startBtn.setEnabled(false);
                                cancelBtn.setEnabled(false);
                                startBtn.setText("SUCCESS");
                            }

                            @Override
                            public void onError(Error error) {
                                startBtn.setText("START");

                                ToastDialog toastDialog = new ToastDialog(MainAbilitySlice.this);
                                toastDialog.setText("some_error_occurred 1").show();
                                progressText.setText("");
                                progressBar.setProgressValue(0);
                                downloadIdFour = 0;
                                cancelBtn.setEnabled(false);
                                progressBar.setIndeterminate(false);
                                startBtn.setEnabled(true);
                            }
                        });
            }
        });
    }

    private void initFiveDownload() {
        ProgressBar progressBar = (ProgressBar) findComponentById(ResourceTable.Id_progressFive);
        Button cancelBtn = (Button) findComponentById(ResourceTable.Id_cancelFive);
        Button startBtn = (Button) findComponentById(ResourceTable.Id_startFive);
        Text progressText = (Text) findComponentById(ResourceTable.Id_progressFiveText);
        cancelBtn.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                PRDownloader.cancel(downloadIdFive);
            }
        });
        startBtn.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                if (Status.RUNNING == PRDownloader.getStatus(downloadIdFive)) {
                    PRDownloader.pause(downloadIdFive);
                    return;
                }

                startBtn.setEnabled(false);
                progressBar.setIndeterminate(true);

                if (Status.PAUSED == PRDownloader.getStatus(downloadIdFive)) {
                    PRDownloader.resume(downloadIdFive);
                    return;
                }

                downloadIdFive = PRDownloader.download(URL5, dirPath, "facebook.apk")
                        .build()
                        .setOnStartOrResumeListener(new OnStartOrResumeListener() {
                            @Override
                            public void onStartOrResume() {
                                progressBar.setIndeterminate(false);
                                startBtn.setEnabled(true);
                                startBtn.setText("PAUSE");
                                cancelBtn.setEnabled(true);
                            }
                        })
                        .setOnPauseListener(new OnPauseListener() {
                            @Override
                            public void onPause() {
                                startBtn.setText("RESTART");
                            }
                        })
                        .setOnCancelListener(new OnCancelListener() {
                            @Override
                            public void onCancel() {
                                startBtn.setText("START");
                                cancelBtn.setEnabled(false);
                                progressBar.setProgressValue(0);
                                progressText.setText("");
                                downloadIdFive = 0;
                                progressBar.setIndeterminate(false);
                            }
                        })
                        .setOnProgressListener(new OnProgressListener() {
                            @Override
                            public void onProgress(Progress progress) {
                                long progressPercent = progress.currentBytes * 100 / progress.totalBytes;
                                progressBar.setProgressValue((int) progressPercent);
                                progressText.setText(Utils.getProgressDisplayLine(progress.currentBytes, progress.totalBytes));
                                progressBar.setIndeterminate(false);
                            }
                        })
                        .start(new OnDownloadListener() {
                            @Override
                            public void onDownloadComplete() {
                                startBtn.setEnabled(false);
                                cancelBtn.setEnabled(false);
                                startBtn.setText("SUCCESS");
                            }

                            @Override
                            public void onError(Error error) {
                                startBtn.setText("START");

                                ToastDialog toastDialog = new ToastDialog(MainAbilitySlice.this);
                                toastDialog.setText("some_error_occurred 1").show();
                                progressText.setText("");
                                progressBar.setProgressValue(0);
                                downloadIdFive = 0;
                                cancelBtn.setEnabled(false);
                                progressBar.setIndeterminate(false);
                                startBtn.setEnabled(true);
                            }
                        });
            }
        });
    }

    private void initSixDownload() {
        ProgressBar progressBar = (ProgressBar) findComponentById(ResourceTable.Id_progressSix);
        Button cancelBtn = (Button) findComponentById(ResourceTable.Id_cancelSix);
        Button startBtn = (Button) findComponentById(ResourceTable.Id_startSix);
        Text progressText = (Text) findComponentById(ResourceTable.Id_progressSixText);
        cancelBtn.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                PRDownloader.cancel(downloadIdSix);
            }
        });
        startBtn.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                if (Status.RUNNING == PRDownloader.getStatus(downloadIdSix)) {
                    PRDownloader.pause(downloadIdSix);
                    return;
                }

                startBtn.setEnabled(false);
                progressBar.setIndeterminate(true);

                if (Status.PAUSED == PRDownloader.getStatus(downloadIdSix)) {
                    PRDownloader.resume(downloadIdSix);
                    return;
                }

                downloadIdSix = PRDownloader.download(URL6, dirPath, "facebook.apk")
                        .build()
                        .setOnStartOrResumeListener(new OnStartOrResumeListener() {
                            @Override
                            public void onStartOrResume() {
                                progressBar.setIndeterminate(false);
                                startBtn.setEnabled(true);
                                startBtn.setText("PAUSE");
                                cancelBtn.setEnabled(true);
                            }
                        })
                        .setOnPauseListener(new OnPauseListener() {
                            @Override
                            public void onPause() {
                                startBtn.setText("RESTART");
                            }
                        })
                        .setOnCancelListener(new OnCancelListener() {
                            @Override
                            public void onCancel() {
                                startBtn.setText("START");
                                cancelBtn.setEnabled(false);
                                progressBar.setProgressValue(0);
                                progressText.setText("");
                                downloadIdSix = 0;
                                progressBar.setIndeterminate(false);
                            }
                        })
                        .setOnProgressListener(new OnProgressListener() {
                            @Override
                            public void onProgress(Progress progress) {
                                long progressPercent = progress.currentBytes * 100 / progress.totalBytes;
                                progressBar.setProgressValue((int) progressPercent);
                                progressText.setText(Utils.getProgressDisplayLine(progress.currentBytes, progress.totalBytes));
                                progressBar.setIndeterminate(false);
                            }
                        })
                        .start(new OnDownloadListener() {
                            @Override
                            public void onDownloadComplete() {
                                startBtn.setEnabled(false);
                                cancelBtn.setEnabled(false);
                                startBtn.setText("SUCCESS");
                            }

                            @Override
                            public void onError(Error error) {
                                startBtn.setText("START");

                                ToastDialog toastDialog = new ToastDialog(MainAbilitySlice.this);
                                toastDialog.setText("some_error_occurred 1").show();
                                progressText.setText("");
                                progressBar.setProgressValue(0);
                                downloadIdSix = 0;
                                cancelBtn.setEnabled(false);
                                progressBar.setIndeterminate(false);
                                startBtn.setEnabled(true);
                            }
                        });
            }
        });
    }

    private void initSevenDownload() {
        ProgressBar progressBar = (ProgressBar) findComponentById(ResourceTable.Id_progressSeven);
        Button cancelBtn = (Button) findComponentById(ResourceTable.Id_cancelSeven);
        Button startBtn = (Button) findComponentById(ResourceTable.Id_startSeven);
        Text progressText = (Text) findComponentById(ResourceTable.Id_progressSevenText);
        cancelBtn.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                PRDownloader.cancel(downloadIdSeven);
            }
        });
        startBtn.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                if (Status.RUNNING == PRDownloader.getStatus(downloadIdSeven)) {
                    PRDownloader.pause(downloadIdSeven);
                    return;
                }

                startBtn.setEnabled(false);
                progressBar.setIndeterminate(true);

                if (Status.PAUSED == PRDownloader.getStatus(downloadIdSeven)) {
                    PRDownloader.resume(downloadIdSeven);
                    return;
                }

                downloadIdSeven = PRDownloader.download(URL7, dirPath, "facebook.apk")
                        .build()
                        .setOnStartOrResumeListener(new OnStartOrResumeListener() {
                            @Override
                            public void onStartOrResume() {
                                progressBar.setIndeterminate(false);
                                startBtn.setEnabled(true);
                                startBtn.setText("PAUSE");
                                cancelBtn.setEnabled(true);
                            }
                        })
                        .setOnPauseListener(new OnPauseListener() {
                            @Override
                            public void onPause() {
                                startBtn.setText("RESTART");
                            }
                        })
                        .setOnCancelListener(new OnCancelListener() {
                            @Override
                            public void onCancel() {
                                startBtn.setText("START");
                                cancelBtn.setEnabled(false);
                                progressBar.setProgressValue(0);
                                progressText.setText("");
                                downloadIdSeven = 0;
                                progressBar.setIndeterminate(false);
                            }
                        })
                        .setOnProgressListener(new OnProgressListener() {
                            @Override
                            public void onProgress(Progress progress) {
                                long progressPercent = progress.currentBytes * 100 / progress.totalBytes;
                                progressBar.setProgressValue((int) progressPercent);
                                progressText.setText(Utils.getProgressDisplayLine(progress.currentBytes, progress.totalBytes));
                                progressBar.setIndeterminate(false);
                            }
                        })
                        .start(new OnDownloadListener() {
                            @Override
                            public void onDownloadComplete() {
                                startBtn.setEnabled(false);
                                cancelBtn.setEnabled(false);
                                startBtn.setText("SUCCESS");
                            }

                            @Override
                            public void onError(Error error) {
                                startBtn.setText("START");

                                ToastDialog toastDialog = new ToastDialog(MainAbilitySlice.this);
                                toastDialog.setText("some_error_occurred 1").show();
                                progressText.setText("");
                                progressBar.setProgressValue(0);
                                downloadIdSeven = 0;
                                cancelBtn.setEnabled(false);
                                progressBar.setIndeterminate(false);
                                startBtn.setEnabled(true);
                            }
                        });
            }
        });
    }

    private void initEightDownload() {
        ProgressBar progressBar = (ProgressBar) findComponentById(ResourceTable.Id_progressEight);
        Button cancelBtn = (Button) findComponentById(ResourceTable.Id_cancelEight);
        Button startBtn = (Button) findComponentById(ResourceTable.Id_startEight);
        Text progressText = (Text) findComponentById(ResourceTable.Id_progressEightText);
        cancelBtn.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                PRDownloader.cancel(downloadIdEight);
            }
        });
        startBtn.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                if (Status.RUNNING == PRDownloader.getStatus(downloadIdEight)) {
                    PRDownloader.pause(downloadIdEight);
                    return;
                }

                startBtn.setEnabled(false);
                progressBar.setIndeterminate(true);

                if (Status.PAUSED == PRDownloader.getStatus(downloadIdEight)) {
                    PRDownloader.resume(downloadIdEight);
                    return;
                }

                downloadIdEight = PRDownloader.download(URL8, dirPath, "facebook.apk")
                        .build()
                        .setOnStartOrResumeListener(new OnStartOrResumeListener() {
                            @Override
                            public void onStartOrResume() {
                                progressBar.setIndeterminate(false);
                                startBtn.setEnabled(true);
                                startBtn.setText("PAUSE");
                                cancelBtn.setEnabled(true);
                            }
                        })
                        .setOnPauseListener(new OnPauseListener() {
                            @Override
                            public void onPause() {
                                startBtn.setText("RESTART");
                            }
                        })
                        .setOnCancelListener(new OnCancelListener() {
                            @Override
                            public void onCancel() {
                                startBtn.setText("START");
                                cancelBtn.setEnabled(false);
                                progressBar.setProgressValue(0);
                                progressText.setText("");
                                downloadIdEight = 0;
                                progressBar.setIndeterminate(false);
                            }
                        })
                        .setOnProgressListener(new OnProgressListener() {
                            @Override
                            public void onProgress(Progress progress) {
                                long progressPercent = progress.currentBytes * 100 / progress.totalBytes;
                                progressBar.setProgressValue((int) progressPercent);
                                progressText.setText(Utils.getProgressDisplayLine(progress.currentBytes, progress.totalBytes));
                                progressBar.setIndeterminate(false);
                            }
                        })
                        .start(new OnDownloadListener() {
                            @Override
                            public void onDownloadComplete() {
                                startBtn.setEnabled(false);
                                cancelBtn.setEnabled(false);
                                startBtn.setText("SUCCESS");
                            }

                            @Override
                            public void onError(Error error) {
                                startBtn.setText("START");

                                ToastDialog toastDialog = new ToastDialog(MainAbilitySlice.this);
                                toastDialog.setText("some_error_occurred 1").show();
                                progressText.setText("");
                                progressBar.setProgressValue(0);
                                downloadIdEight = 0;
                                cancelBtn.setEnabled(false);
                                progressBar.setIndeterminate(false);
                                startBtn.setEnabled(true);
                            }
                        });
            }
        });
    }

    private void initNineDownload() {
        ProgressBar progressBar = (ProgressBar) findComponentById(ResourceTable.Id_progressNine);
        Button cancelBtn = (Button) findComponentById(ResourceTable.Id_cancelNine);
        Button startBtn = (Button) findComponentById(ResourceTable.Id_startNine);
        Text progressText = (Text) findComponentById(ResourceTable.Id_progressNineText);
        cancelBtn.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                PRDownloader.cancel(downloadIdNine);
            }
        });
        startBtn.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                if (Status.RUNNING == PRDownloader.getStatus(downloadIdNine)) {
                    PRDownloader.pause(downloadIdNine);
                    return;
                }

                startBtn.setEnabled(false);
                progressBar.setIndeterminate(true);

                if (Status.PAUSED == PRDownloader.getStatus(downloadIdNine)) {
                    PRDownloader.resume(downloadIdNine);
                    return;
                }

                downloadIdNine = PRDownloader.download(URL9, dirPath, "facebook.apk")
                        .build()
                        .setOnStartOrResumeListener(new OnStartOrResumeListener() {
                            @Override
                            public void onStartOrResume() {
                                progressBar.setIndeterminate(false);
                                startBtn.setEnabled(true);
                                startBtn.setText("PAUSE");
                                cancelBtn.setEnabled(true);
                            }
                        })
                        .setOnPauseListener(new OnPauseListener() {
                            @Override
                            public void onPause() {
                                startBtn.setText("RESTART");
                            }
                        })
                        .setOnCancelListener(new OnCancelListener() {
                            @Override
                            public void onCancel() {
                                startBtn.setText("START");
                                cancelBtn.setEnabled(false);
                                progressBar.setProgressValue(0);
                                progressText.setText("");
                                downloadIdNine = 0;
                                progressBar.setIndeterminate(false);
                            }
                        })
                        .setOnProgressListener(new OnProgressListener() {
                            @Override
                            public void onProgress(Progress progress) {
                                long progressPercent = progress.currentBytes * 100 / progress.totalBytes;
                                progressBar.setProgressValue((int) progressPercent);
                                progressText.setText(Utils.getProgressDisplayLine(progress.currentBytes, progress.totalBytes));
                                progressBar.setIndeterminate(false);
                            }
                        })
                        .start(new OnDownloadListener() {
                            @Override
                            public void onDownloadComplete() {
                                startBtn.setEnabled(false);
                                cancelBtn.setEnabled(false);
                                startBtn.setText("SUCCESS");
                            }

                            @Override
                            public void onError(Error error) {
                                startBtn.setText("START");

                                ToastDialog toastDialog = new ToastDialog(MainAbilitySlice.this);
                                toastDialog.setText("some_error_occurred 1").show();
                                progressText.setText("");
                                progressBar.setProgressValue(0);
                                downloadIdNine = 0;
                                cancelBtn.setEnabled(false);
                                progressBar.setIndeterminate(false);
                                startBtn.setEnabled(true);
                            }
                        });
            }
        });
    }

    private void initTenDownload() {
        ProgressBar progressBar = (ProgressBar) findComponentById(ResourceTable.Id_progressTen);
        Button cancelBtn = (Button) findComponentById(ResourceTable.Id_cancelTen);
        Button startBtn = (Button) findComponentById(ResourceTable.Id_startTen);
        Text progressText = (Text) findComponentById(ResourceTable.Id_progressTenText);
        cancelBtn.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                PRDownloader.cancel(downloadIdTen);
            }
        });
        startBtn.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                if (Status.RUNNING == PRDownloader.getStatus(downloadIdTen)) {
                    PRDownloader.pause(downloadIdTen);
                    return;
                }

                startBtn.setEnabled(false);
                progressBar.setIndeterminate(true);

                if (Status.PAUSED == PRDownloader.getStatus(downloadIdTen)) {
                    PRDownloader.resume(downloadIdTen);
                    return;
                }

                downloadIdTen = PRDownloader.download(URL10, dirPath, "facebook.apk")
                        .build()
                        .setOnStartOrResumeListener(new OnStartOrResumeListener() {
                            @Override
                            public void onStartOrResume() {
                                progressBar.setIndeterminate(false);
                                startBtn.setEnabled(true);
                                startBtn.setText("PAUSE");
                                cancelBtn.setEnabled(true);
                            }
                        })
                        .setOnPauseListener(new OnPauseListener() {
                            @Override
                            public void onPause() {
                                startBtn.setText("RESTART");
                            }
                        })
                        .setOnCancelListener(new OnCancelListener() {
                            @Override
                            public void onCancel() {
                                startBtn.setText("START");
                                cancelBtn.setEnabled(false);
                                progressBar.setProgressValue(0);
                                progressText.setText("");
                                downloadIdTen = 0;
                                progressBar.setIndeterminate(false);
                            }
                        })
                        .setOnProgressListener(new OnProgressListener() {
                            @Override
                            public void onProgress(Progress progress) {
                                long progressPercent = progress.currentBytes * 100 / progress.totalBytes;
                                progressBar.setProgressValue((int) progressPercent);
                                progressText.setText(Utils.getProgressDisplayLine(progress.currentBytes, progress.totalBytes));
                                progressBar.setIndeterminate(false);
                            }
                        })
                        .start(new OnDownloadListener() {
                            @Override
                            public void onDownloadComplete() {
                                startBtn.setEnabled(false);
                                cancelBtn.setEnabled(false);
                                startBtn.setText("SUCCESS");
                            }

                            @Override
                            public void onError(Error error) {
                                startBtn.setText("START");

                                ToastDialog toastDialog = new ToastDialog(MainAbilitySlice.this);
                                toastDialog.setText("some_error_occurred 1").show();
                                progressText.setText("");
                                progressBar.setProgressValue(0);
                                downloadIdTen = 0;
                                cancelBtn.setEnabled(false);
                                progressBar.setIndeterminate(false);
                                startBtn.setEnabled(true);
                            }
                        });
            }
        });
    }

    private void initElevenDownload() {
        ProgressBar progressBar = (ProgressBar) findComponentById(ResourceTable.Id_progressEleven);
        Button cancelBtn = (Button) findComponentById(ResourceTable.Id_cancelEleven);
        Button startBtn = (Button) findComponentById(ResourceTable.Id_startEleven);
        Text progressText = (Text) findComponentById(ResourceTable.Id_progressElevenText);
        cancelBtn.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                PRDownloader.cancel(downloadIdEleven);
            }
        });
        startBtn.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                if (Status.RUNNING == PRDownloader.getStatus(downloadIdEleven)) {
                    PRDownloader.pause(downloadIdEleven);
                    return;
                }

                startBtn.setEnabled(false);
                progressBar.setIndeterminate(true);

                if (Status.PAUSED == PRDownloader.getStatus(downloadIdEleven)) {
                    PRDownloader.resume(downloadIdEleven);
                    return;
                }

                downloadIdEleven = PRDownloader.download(URL11, dirPath, "facebook.apk")
                        .build()
                        .setOnStartOrResumeListener(new OnStartOrResumeListener() {
                            @Override
                            public void onStartOrResume() {
                                progressBar.setIndeterminate(false);
                                startBtn.setEnabled(true);
                                startBtn.setText("PAUSE");
                                cancelBtn.setEnabled(true);
                            }
                        })
                        .setOnPauseListener(new OnPauseListener() {
                            @Override
                            public void onPause() {
                                startBtn.setText("RESTART");
                            }
                        })
                        .setOnCancelListener(new OnCancelListener() {
                            @Override
                            public void onCancel() {
                                startBtn.setText("START");
                                cancelBtn.setEnabled(false);
                                progressBar.setProgressValue(0);
                                progressText.setText("");
                                downloadIdEleven = 0;
                                progressBar.setIndeterminate(false);
                            }
                        })
                        .setOnProgressListener(new OnProgressListener() {
                            @Override
                            public void onProgress(Progress progress) {
                                long progressPercent = progress.currentBytes * 100 / progress.totalBytes;
                                progressBar.setProgressValue((int) progressPercent);
                                progressText.setText(Utils.getProgressDisplayLine(progress.currentBytes, progress.totalBytes));
                                progressBar.setIndeterminate(false);
                            }
                        })
                        .start(new OnDownloadListener() {
                            @Override
                            public void onDownloadComplete() {
                                startBtn.setEnabled(false);
                                cancelBtn.setEnabled(false);
                                startBtn.setText("SUCCESS");
                            }

                            @Override
                            public void onError(Error error) {
                                startBtn.setText("START");

                                ToastDialog toastDialog = new ToastDialog(MainAbilitySlice.this);
                                toastDialog.setText("some_error_occurred 1").show();
                                progressText.setText("");
                                progressBar.setProgressValue(0);
                                downloadIdEleven = 0;
                                cancelBtn.setEnabled(false);
                                progressBar.setIndeterminate(false);
                                startBtn.setEnabled(true);
                            }
                        });
            }
        });
    }

    private void initTwelveDownload() {
        ProgressBar progressBar = (ProgressBar) findComponentById(ResourceTable.Id_progressTwelve);
        Button cancelBtn = (Button) findComponentById(ResourceTable.Id_cancelTwelve);
        Button startBtn = (Button) findComponentById(ResourceTable.Id_startTwelve);
        Text progressText = (Text) findComponentById(ResourceTable.Id_progressTwelveText);
        cancelBtn.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                PRDownloader.cancel(downloadIdTwelve);
            }
        });
        startBtn.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                if (Status.RUNNING == PRDownloader.getStatus(downloadIdTwelve)) {
                    PRDownloader.pause(downloadIdTwelve);
                    return;
                }

                startBtn.setEnabled(false);
                progressBar.setIndeterminate(true);

                if (Status.PAUSED == PRDownloader.getStatus(downloadIdTwelve)) {
                    PRDownloader.resume(downloadIdTwelve);
                    return;
                }

                downloadIdTwelve = PRDownloader.download(URL12, dirPath, "facebook.apk")
                        .build()
                        .setOnStartOrResumeListener(new OnStartOrResumeListener() {
                            @Override
                            public void onStartOrResume() {
                                progressBar.setIndeterminate(false);
                                startBtn.setEnabled(true);
                                startBtn.setText("PAUSE");
                                cancelBtn.setEnabled(true);
                            }
                        })
                        .setOnPauseListener(new OnPauseListener() {
                            @Override
                            public void onPause() {
                                startBtn.setText("RESTART");
                            }
                        })
                        .setOnCancelListener(new OnCancelListener() {
                            @Override
                            public void onCancel() {
                                startBtn.setText("START");
                                cancelBtn.setEnabled(false);
                                progressBar.setProgressValue(0);
                                progressText.setText("");
                                downloadIdTwelve = 0;
                                progressBar.setIndeterminate(false);
                            }
                        })
                        .setOnProgressListener(new OnProgressListener() {
                            @Override
                            public void onProgress(Progress progress) {
                                long progressPercent = progress.currentBytes * 100 / progress.totalBytes;
                                progressBar.setProgressValue((int) progressPercent);
                                progressText.setText(Utils.getProgressDisplayLine(progress.currentBytes, progress.totalBytes));
                                progressBar.setIndeterminate(false);
                            }
                        })
                        .start(new OnDownloadListener() {
                            @Override
                            public void onDownloadComplete() {
                                startBtn.setEnabled(false);
                                cancelBtn.setEnabled(false);
                                startBtn.setText("SUCCESS");
                            }

                            @Override
                            public void onError(Error error) {
                                startBtn.setText("START");

                                ToastDialog toastDialog = new ToastDialog(MainAbilitySlice.this);
                                toastDialog.setText("some_error_occurred 1").show();
                                progressText.setText("");
                                progressBar.setProgressValue(0);
                                downloadIdTwelve = 0;
                                cancelBtn.setEnabled(false);
                                progressBar.setIndeterminate(false);
                                startBtn.setEnabled(true);
                            }
                        });
            }
        });
    }

    private void initThirteenDownload() {
        ProgressBar progressBar = (ProgressBar) findComponentById(ResourceTable.Id_progressThirteen);
        Button cancelBtn = (Button) findComponentById(ResourceTable.Id_cancelThirteen);
        Button startBtn = (Button) findComponentById(ResourceTable.Id_startThirteen);
        Text progressText = (Text) findComponentById(ResourceTable.Id_progressThirteenText);
        cancelBtn.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                PRDownloader.cancel(downloadIdThirteen);
            }
        });
        startBtn.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                if (Status.RUNNING == PRDownloader.getStatus(downloadIdThirteen)) {
                    PRDownloader.pause(downloadIdThirteen);
                    return;
                }

                startBtn.setEnabled(false);
                progressBar.setIndeterminate(true);

                if (Status.PAUSED == PRDownloader.getStatus(downloadIdThirteen)) {
                    PRDownloader.resume(downloadIdThirteen);
                    return;
                }

                downloadIdThirteen = PRDownloader.download(URL13, dirPath, "facebook.apk")
                        .build()
                        .setOnStartOrResumeListener(new OnStartOrResumeListener() {
                            @Override
                            public void onStartOrResume() {
                                progressBar.setIndeterminate(false);
                                startBtn.setEnabled(true);
                                startBtn.setText("PAUSE");
                                cancelBtn.setEnabled(true);
                            }
                        })
                        .setOnPauseListener(new OnPauseListener() {
                            @Override
                            public void onPause() {
                                startBtn.setText("RESTART");
                            }
                        })
                        .setOnCancelListener(new OnCancelListener() {
                            @Override
                            public void onCancel() {
                                startBtn.setText("START");
                                cancelBtn.setEnabled(false);
                                progressBar.setProgressValue(0);
                                progressText.setText("");
                                downloadIdThirteen = 0;
                                progressBar.setIndeterminate(false);
                            }
                        })
                        .setOnProgressListener(new OnProgressListener() {
                            @Override
                            public void onProgress(Progress progress) {
                                long progressPercent = progress.currentBytes * 100 / progress.totalBytes;
                                progressBar.setProgressValue((int) progressPercent);
                                progressText.setText(Utils.getProgressDisplayLine(progress.currentBytes, progress.totalBytes));
                                progressBar.setIndeterminate(false);
                            }
                        })
                        .start(new OnDownloadListener() {
                            @Override
                            public void onDownloadComplete() {
                                startBtn.setEnabled(false);
                                cancelBtn.setEnabled(false);
                                startBtn.setText("SUCCESS");
                            }

                            @Override
                            public void onError(Error error) {
                                startBtn.setText("START");

                                ToastDialog toastDialog = new ToastDialog(MainAbilitySlice.this);
                                toastDialog.setText("some_error_occurred 1").show();
                                progressText.setText("");
                                progressBar.setProgressValue(0);
                                downloadIdThirteen = 0;
                                cancelBtn.setEnabled(false);
                                progressBar.setIndeterminate(false);
                                startBtn.setEnabled(true);
                            }
                        });
            }
        });
    }

    private void initFourteenDownload() {
        ProgressBar progressBar = (ProgressBar) findComponentById(ResourceTable.Id_progressFourteen);
        Button cancelBtn = (Button) findComponentById(ResourceTable.Id_cancelFourteen);
        Button startBtn = (Button) findComponentById(ResourceTable.Id_startFourteen);
        Text progressText = (Text) findComponentById(ResourceTable.Id_progressFourteenText);
        cancelBtn.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                PRDownloader.cancel(downloadIdFourteen);
            }
        });
        startBtn.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                if (Status.RUNNING == PRDownloader.getStatus(downloadIdFourteen)) {
                    PRDownloader.pause(downloadIdFourteen);
                    return;
                }

                startBtn.setEnabled(false);
                progressBar.setIndeterminate(true);

                if (Status.PAUSED == PRDownloader.getStatus(downloadIdFourteen)) {
                    PRDownloader.resume(downloadIdFourteen);
                    return;
                }

                downloadIdFourteen = PRDownloader.download(URL14, dirPath, "facebook.apk")
                        .build()
                        .setOnStartOrResumeListener(new OnStartOrResumeListener() {
                            @Override
                            public void onStartOrResume() {
                                progressBar.setIndeterminate(false);
                                startBtn.setEnabled(true);
                                startBtn.setText("PAUSE");
                                cancelBtn.setEnabled(true);
                            }
                        })
                        .setOnPauseListener(new OnPauseListener() {
                            @Override
                            public void onPause() {
                                startBtn.setText("RESTART");
                            }
                        })
                        .setOnCancelListener(new OnCancelListener() {
                            @Override
                            public void onCancel() {
                                startBtn.setText("START");
                                cancelBtn.setEnabled(false);
                                progressBar.setProgressValue(0);
                                progressText.setText("");
                                downloadIdFourteen = 0;
                                progressBar.setIndeterminate(false);
                            }
                        })
                        .setOnProgressListener(new OnProgressListener() {
                            @Override
                            public void onProgress(Progress progress) {
                                long progressPercent = progress.currentBytes * 100 / progress.totalBytes;
                                progressBar.setProgressValue((int) progressPercent);
                                progressText.setText(Utils.getProgressDisplayLine(progress.currentBytes, progress.totalBytes));
                                progressBar.setIndeterminate(false);
                            }
                        })
                        .start(new OnDownloadListener() {
                            @Override
                            public void onDownloadComplete() {
                                startBtn.setEnabled(false);
                                cancelBtn.setEnabled(false);
                                startBtn.setText("SUCCESS");
                            }

                            @Override
                            public void onError(Error error) {
                                startBtn.setText("START");

                                ToastDialog toastDialog = new ToastDialog(MainAbilitySlice.this);
                                toastDialog.setText("some_error_occurred 1").show();
                                progressText.setText("");
                                progressBar.setProgressValue(0);
                                downloadIdFourteen = 0;
                                cancelBtn.setEnabled(false);
                                progressBar.setIndeterminate(false);
                                startBtn.setEnabled(true);
                            }
                        });
            }
        });
    }

    private void initFifteenDownload() {
        ProgressBar progressBar = (ProgressBar) findComponentById(ResourceTable.Id_progressFifteen);
        Button cancelBtn = (Button) findComponentById(ResourceTable.Id_cancelFifteen);
        Button startBtn = (Button) findComponentById(ResourceTable.Id_startFifteen);
        Text progressText = (Text) findComponentById(ResourceTable.Id_progressFifteenText);
        cancelBtn.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                PRDownloader.cancel(downloadIdFifteen);
            }
        });
        startBtn.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                if (Status.RUNNING == PRDownloader.getStatus(downloadIdFifteen)) {
                    PRDownloader.pause(downloadIdFifteen);
                    return;
                }

                startBtn.setEnabled(false);
                progressBar.setIndeterminate(true);

                if (Status.PAUSED == PRDownloader.getStatus(downloadIdFifteen)) {
                    PRDownloader.resume(downloadIdFifteen);
                    return;
                }

                downloadIdFifteen = PRDownloader.download(URL15, dirPath, "facebook.apk")
                        .build()
                        .setOnStartOrResumeListener(new OnStartOrResumeListener() {
                            @Override
                            public void onStartOrResume() {
                                progressBar.setIndeterminate(false);
                                startBtn.setEnabled(true);
                                startBtn.setText("PAUSE");
                                cancelBtn.setEnabled(true);
                            }
                        })
                        .setOnPauseListener(new OnPauseListener() {
                            @Override
                            public void onPause() {
                                startBtn.setText("RESTART");
                            }
                        })
                        .setOnCancelListener(new OnCancelListener() {
                            @Override
                            public void onCancel() {
                                startBtn.setText("START");
                                cancelBtn.setEnabled(false);
                                progressBar.setProgressValue(0);
                                progressText.setText("");
                                downloadIdFifteen = 0;
                                progressBar.setIndeterminate(false);
                            }
                        })
                        .setOnProgressListener(new OnProgressListener() {
                            @Override
                            public void onProgress(Progress progress) {
                                long progressPercent = progress.currentBytes * 100 / progress.totalBytes;
                                progressBar.setProgressValue((int) progressPercent);
                                progressText.setText(Utils.getProgressDisplayLine(progress.currentBytes, progress.totalBytes));
                                progressBar.setIndeterminate(false);
                            }
                        })
                        .start(new OnDownloadListener() {
                            @Override
                            public void onDownloadComplete() {
                                startBtn.setEnabled(false);
                                cancelBtn.setEnabled(false);
                                startBtn.setText("SUCCESS");
                            }

                            @Override
                            public void onError(Error error) {
                                startBtn.setText("START");

                                ToastDialog toastDialog = new ToastDialog(MainAbilitySlice.this);
                                toastDialog.setText("some_error_occurred 1").show();
                                progressText.setText("");
                                progressBar.setProgressValue(0);
                                downloadIdFifteen = 0;
                                cancelBtn.setEnabled(false);
                                progressBar.setIndeterminate(false);
                                startBtn.setEnabled(true);
                            }
                        });
            }
        });
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
